package com.blog.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;

import com.blog.domain.Blog;
import com.blog.domain.Category;
import com.blog.domain.Comment;
import com.blog.page.CommonList;
import com.blog.service.BlogService;
public class BaseAction {

	protected int pageNo = 1; // 当前页
	protected int resultSize = 0; // 总记录数
	protected int pageSize = 10;// 分页记录	
	protected CommonList commonList;// 自定义分页对象
	@Autowired
	BlogService blogService;	
	
	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getResultSize() {
		return resultSize;
	}

	public void setResultSize(int resultSize) {
		this.resultSize = resultSize;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public CommonList getCommonList() {
		return commonList;
	}

	public void setCommonList(CommonList commonList) {
		this.commonList = commonList;
	}

	protected CommonList createCommonList() {
		return new CommonList(resultSize, pageNo, pageSize);
	}
	
	public void homeSiderData(Integer id,ModelMap modelMap){
		Blog topblog = null;
		if(id==null){    
			topblog= blogService.queryTopBlog();        
		}else{
			topblog= blogService.queryBlog(id);
		}
		modelMap.put("topBlog", topblog);
        if(topblog!=null){
        	List<Comment> bcom = blogService.queryComments(topblog.getId());
            modelMap.put("bcom", bcom);
            modelMap.put("comnum", bcom.size());  
        }
		List<Blog> blogs= blogService.queryBlogs(0,5);
		List<Category> categorys = blogService.queryCategorys();
		List<Comment> comments = blogService.queryFirst10Comments();        
        modelMap.put("categorys", categorys);
        modelMap.put("blogs", blogs);
        modelMap.put("comments", comments); 
	}
}
